#include "findfiledialog.h"
#include "ui_findfiledialog.h"
#include "workbench.h"
#include <QtGui>

FindFileDialog::FindFileDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    setWindowTitle("File finder");

    model = new QFileSystemModel;
    model->setRootPath("");

    ui->treeView->setModel(model);
    for (int i = 1; i < 10; i++)
    {
        ui->treeView->hideColumn(i);
    }

    ui->treeView->setIndentation(20);
    ui->treeView->setSortingEnabled(true);
    ui->treeView->setExpandsOnDoubleClick(false);

    connect(ui->treeView, SIGNAL(clicked(const QModelIndex&)), this, SLOT(itemClicked(const QModelIndex&)));

}

FindFileDialog::~FindFileDialog()
{
    delete ui;
    delete model;
}

void FindFileDialog::on_buttonBox_rejected()
{
    this->close();
}

void FindFileDialog::on_buttonBox_accepted()
{
//    m_projectFolder = m_filepath;
    this->close();
}

void FindFileDialog::itemClicked(const QModelIndex &m_index)
{
    ui->treeView->setExpanded(m_index, (!ui->treeView->isExpanded(m_index)));
    m_filepath = model->filePath(m_index);
}

